#include <iostream>

#include "ros/ros.h"
#include "demo/Login.h"

bool ServiceCallback(demo::Login::Request &request, demo::Login::Response &response) {
    if (request.username == "admin" && request.password == "admin") {
        response.result = "Login success";
        ROS_INFO("%s", response.result.c_str());
        return true;
    }
    response.result = "Login failed";
    ROS_ERROR("%s", response.result.c_str());
    return true;
}

int main(int argc, char* argv[]) {
    std::string nodeName = "Server";
    ros::init(argc, argv, nodeName);
    ros::NodeHandle nodeHandle;
    std::string serviceName = "demo4";
    const ros::ServiceServer &serviceServer = nodeHandle.advertiseService(serviceName, ServiceCallback); // 创建服务端
    ros::spin();

    return EXIT_SUCCESS;
}
